"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mongodb_1 = require("mongodb"); // 增加ObjectId导入
const Global_1 = require("../models/Global");
async function default_1(call) {
    // 转换为ObjectId
    const _id = new mongodb_1.ObjectId(call.req._id);
    try {
        // 1. 先查询原数据
        const originData = await Global_1.Global.db.collection("houtai").findOne({ _id });
        if (!originData) {
            call.error('数据不存在');
            return;
        }
        // 2. 插入回收站集合（添加删除时间戳）
        await Global_1.Global.db.collection("Recycle").insertOne({
            ...originData,
            deletedAt: new Date()
        });
        // 3. 执行原删除操作
        const op = await Global_1.Global.db.collection("houtai").deleteOne({ _id });
        call.succ({
            _id: call.req._id.toString()
        });
    }
    catch (err) {
        console.error('删除失败', err);
        call.error('删除失败，请稍后重试');
    }
}
exports.default = default_1;
